
import math

def collatz(n, i=0):
	#print(n)
	i +=1
	r = 0
	if n<=1:
		print("chain length:"+str(i)) 
		return i #base
	if n%4==0: 
		r = math.ceil(n/4)
		i+=1
	elif n%2==0: 
		r = math.ceil(n/2)
	else: 
		r = math.ceil((3*n+1)/2)
		i+=1
	return collatz(r,i)

assert(collatz(13)==10)
#chains = []
#for i in range(1000000):
#	chains.append( collatz(i) )

chains = map(collatz, [i for i in range(1000000)]) #not tested
max_chain = max(chains)
print(chains.index(max_chain))

